﻿#include "prj_manager_detail_widget.h"
#include "ui_prj_manager_detail_widget.h"
#include <QUuid>
#include <QDebug>

PrjManagerDetailWidget::PrjManagerDetailWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PrjManagerDetailWidget),
    m_prjManagerOverviewWidget(new ProjectOverviewWidget),
    m_prjManagerRequirementWidget(new RequirementManagementWidget),
    m_prjManagerTaskWidget(new PrjManagerTaskWidget),
    m_prjManagerTestWidget(new PrjManagerTestWidget),
    m_versionManagementWidget(new VersionManagementWidget)
{
    ui->setupUi(this);
    initUi();
    initEvents();
}

PrjManagerDetailWidget::~PrjManagerDetailWidget()
{
    delete ui;
}

void PrjManagerDetailWidget::setProject(QString prjName, QString uuid)
{
    ui->prjNameLabel->setText(prjName);
    m_prjUuid = uuid;

    m_prjManagerOverviewWidget->setPrjUuid(uuid);
    ui->stackedWidget->setCurrentWidget(m_prjManagerOverviewWidget);
    ui->prjManagerOverviewBtn->setChecked(true);
}

void PrjManagerDetailWidget::initUi()
{
    ui->stackedWidget->addWidget(m_prjManagerOverviewWidget);
    ui->stackedWidget->addWidget(m_prjManagerRequirementWidget);
    ui->stackedWidget->addWidget(m_prjManagerTaskWidget);
    ui->stackedWidget->addWidget(m_prjManagerTestWidget);
    ui->stackedWidget->addWidget(m_versionManagementWidget);

    ui->stackedWidget->setCurrentWidget(m_prjManagerOverviewWidget);
    ui->prjManagerOverviewBtn->setChecked(true);
}

void PrjManagerDetailWidget::initEvents()
{
    connect(ui->prjBtn, &QPushButton::clicked, this, [=]() {
        emit(backToPrj());
    });
    connect(ui->prjManagerOverviewBtn, &QPushButton::clicked, this, [=]() {
        m_prjManagerOverviewWidget->setPrjUuid(m_prjUuid);
        ui->stackedWidget->setCurrentWidget(m_prjManagerOverviewWidget);
    });
    connect(ui->prjManagerRequirementBtn, &QPushButton::clicked, this, [=]() {
        m_prjManagerRequirementWidget->setPrjUuid(m_prjUuid);
        ui->stackedWidget->setCurrentWidget(m_prjManagerRequirementWidget);
    });
    connect(ui->prjManagerTaskBtn, &QPushButton::clicked, this, [=]() {
        m_prjManagerTaskWidget->setPrjUuid(m_prjUuid);
        ui->stackedWidget->setCurrentWidget(m_prjManagerTaskWidget);
    });
    connect(ui->prjManagerTestBtn, &QPushButton::clicked, this, [=]() {
        ui->stackedWidget->setCurrentWidget(m_prjManagerTestWidget);
    });
    connect(ui->versionBtn, &QPushButton::clicked, this, [=]() {
        ui->stackedWidget->setCurrentWidget(m_versionManagementWidget);
    });
}
